package com.hanhai;

import java.nio.channels.NonWritableChannelException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

/**
 * @author weijingchen
 * @DateTime 2025-05-26
 */
public class LocalTimeTest {
    public static void main(String[] args) {
        //1、获取当前时间
        LocalTime now = LocalTime.now();
        System.out.println("当前时间是" + now);

        //2、获取指定时间
        LocalTime time = LocalTime.of(11, 56, 21);
        System.out.println("指定时间是" + time);

        System.out.println("----------------------time:11:56:21------------------------------------");
        //3、获取指定时间的时分秒
        int hour = time.getHour();
        int minute = time.getMinute();
        int second = time.getSecond();
        int nano = time.getNano();
        System.out.println("指定时间的时：" + hour + "分：" + minute + "秒：" + second + "纳秒：" + nano);

        //4、isBefore/isAfter
        System.out.println("----------------------time:11:56:21------------------------------------");

        boolean before = time.isBefore(now);
        System.out.println("time是否早于now：" + before);
        boolean after = time.isAfter(now);
        System.out.println("time是否晚于now：" + after);
        //5、plusXxx 增加
        System.out.println("----------------------time:11:56:21------------------------------------");
        LocalTime plus1 = time.plus(1, ChronoUnit.HOURS);
        System.out.println("增加1小时后的时间是" + plus1);
        LocalTime plus2 = time.plus(1, ChronoUnit.MINUTES);
        System.out.println("增加1分钟后的时间是" + plus2);
        LocalTime plus3 = time.plus(1, ChronoUnit.SECONDS);
        System.out.println("增加1秒后的时间是" + plus3);
        LocalTime plus4 = time.plus(1, ChronoUnit.MILLIS);
        System.out.println("增加1毫秒后的时间是" + plus4);
        LocalTime plus5 = time.plus(1, ChronoUnit.NANOS);
        System.out.println("增加1纳秒后的时间是" + plus5);
        //6、minusXxx 减少
        System.out.println("----------------------time:11:56:21------------------------------------");

        LocalTime minus1 = time.minus(1, ChronoUnit.HOURS);
        System.out.println("减少1小时后的时间是" + minus1);
        LocalTime minus2 = time.minus(1, ChronoUnit.MINUTES);
        System.out.println("减少1分钟后的时间是" + minus2);
        LocalTime minus3 = time.minus(1, ChronoUnit.SECONDS);
        System.out.println("减少1秒后的时间是" + minus3);
        LocalTime minus4 = time.minus(1, ChronoUnit.MILLIS);
        System.out.println("减少1毫秒后的时间是" + minus4);
        LocalTime minus5 = time.minus(1, ChronoUnit.NANOS);
        System.out.println("减少1纳秒后的时间是" + minus5);
        //7、withXxx 修改
        System.out.println("----------------------time:11:56:21------------------------------------");
        LocalTime with1 = time.withHour(12);
        System.out.println("修改小时后的时间是" + with1);
        LocalTime with2 = time.withMinute(12);
        System.out.println("修改分钟后的时间是" + with2);
        LocalTime with3 = time.withSecond(12);
        System.out.println("修改秒后的时间是" + with3);
        LocalTime with4 = time.withNano(12);
        System.out.println("修改纳秒后的时间是" + with4);
        LocalTime with5 = time.with(LocalTime.of(12, 12, 12));
        System.out.println("修改后的时间是" + with5);

        LocalTime max = LocalTime.MAX;
        System.out.println("最大值是" + max);
        LocalTime min = LocalTime.MIN;
        System.out.println("最小值是" + min);

        LocalDateTime max1 = LocalDateTime.MAX;
        System.out.println("最大值是" + max1);
        LocalDateTime min1 = LocalDateTime.MIN;
        System.out.println("最小值是" + min1);


        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        System.out.println(localDateTime);
        LocalDate begin = LocalDate.of(2024, 5, 20);
        LocalDate end = LocalDate.of(2025, 5, 25);
        List<LocalDate> dateList = getDateList(begin, end);
        for (LocalDate localDate : dateList) {
            System.out.println(localDate);
        }
    }

    private static List<LocalDate> getDateList(LocalDate begin, LocalDate end) {
        List<LocalDate> list = new ArrayList<>();
        list.add(begin);
        while (begin.isBefore(end)) {
            begin = begin.plusDays(1);
            list.add(begin);
        }
        return list;
    }
}
